package domain;

import java.util.Collection;
import java.util.Date;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;
import javax.validation.constraints.Pattern;

import org.hibernate.validator.constraints.NotBlank;
import org.springframework.format.annotation.DateTimeFormat;


@Entity
@Access(AccessType.PROPERTY)

public class Project extends DomainEntity{

	// Constructors -----------------------------------------------------------
	
	public Project() {
		super();
		// TODO Auto-generated constructor stub
	}
	
	// Attributes -------------------------------------------------------------
	
	private String referenceNumber;
	private String title;
	private String goal;
	private Date creationMoment;
	private Date startMoment;
	private Date finishMoment;
	private String description;
	private String state;
	private Double amountOfWork;
	
	@Pattern(regexp="^(\\w+)$")
	public String getReferenceNumber() {
		return referenceNumber;
	}
	public void setReferenceNumber(String referenceNumber) {
		this.referenceNumber = referenceNumber;
	}
	
	@NotBlank
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	
	@NotNull
	@Temporal(TemporalType.TIMESTAMP)
	@DateTimeFormat(pattern = "yyyy/MM/dd HH:mm")
	public Date getStartMoment() {
		return startMoment;
	}
	public void setStartMoment(Date startMoment) {
		this.startMoment = startMoment;
	}
	
	@NotBlank
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	
	@NotBlank
	public String getGoal() {
		return goal;
	}
	public void setGoal(String goal) {
		this.goal = goal;
	}
	
	@NotNull
	@Temporal(TemporalType.TIMESTAMP)
	@DateTimeFormat(pattern = "yyyy/MM/dd HH:mm")
	@Past
	public Date getCreationMoment() {
		return creationMoment;
	}
	public void setCreationMoment(Date creationMoment) {
		this.creationMoment = creationMoment;
	}
	@NotNull
	@Temporal(TemporalType.TIMESTAMP)
	@DateTimeFormat(pattern = "yyyy/MM/dd HH:mm")
	public Date getFinishMoment() {
		return finishMoment;
	}
	public void setFinishMoment(Date finishMoment) {
		this.finishMoment = finishMoment;
	}
	
	public String getState() {
		return state;
	}
	public void setState(String state) {
		this.state = state;
	}
	
	@Min(0)
	public Double getAmountOfWork() {
		return amountOfWork;
	}
	public void setAmountOfWork(Double amountOfWork) {
		this.amountOfWork = amountOfWork;
	}
	// Relationships ----------------------------------------------------------
	
	private User creator;
	private Collection<Registration> registrations;
	private Collection<Requirement> requirements;
	
	@NotNull
	@Valid
	@ManyToOne(optional = false)
	public User getCreator() {
		return creator;
	}
	public void setCreator(User creator) {
		this.creator = creator;
	}
	

	@Valid
	@OneToMany(mappedBy="project")
	public Collection<Registration> getRegistrations() {
		return registrations;
	}
	
	public void setRegistrations(Collection<Registration> registrations) {
		this.registrations = registrations;
	}
	
	@Valid
	@OneToMany(mappedBy="project")
	public Collection<Requirement> getRequirements() {
		return requirements;
	}
	public void setRequirements(Collection<Requirement> requirements) {
		this.requirements = requirements;
	}
	
	
	
	
	
	

}
